package cn.iocoder.yudao.module.trade.service.fruitcard;

import cn.iocoder.yudao.module.trade.controller.admin.fruitcard.vo.FruitCardDetailCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.fruitcard.vo.FruitCardDetailExportReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.fruitcard.vo.FruitCardDetailPageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.fruitcard.vo.FruitCardDetailUpdateReqVO;
import cn.iocoder.yudao.module.trade.convert.fruitcard.FruitCardDetailConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.fruitcard.FruitCardDetailMapper;
import cn.iocoder.yudao.module.trade.dal.mysql.fruitcard.FruitCardDetailDO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 水果卡 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class FruitCardDetailServiceImpl implements FruitCardDetailService {

    @Resource
    private FruitCardDetailMapper cardDetailMapper;

    @Override
    public Long createCardDetail(FruitCardDetailCreateReqVO createReqVO) {
        // 插入
        FruitCardDetailDO cardDetail = FruitCardDetailConvert.INSTANCE.convert(createReqVO);
        cardDetailMapper.insert(cardDetail);
        // 返回
        return cardDetail.getId();
    }

    @Override
    public void updateCardDetail(FruitCardDetailUpdateReqVO updateReqVO) {
        // 校验存在
        validateCardDetailExists(updateReqVO.getId());
        // 更新
        FruitCardDetailDO updateObj = FruitCardDetailConvert.INSTANCE.convert(updateReqVO);
        cardDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteCardDetail(Long id) {
        // 校验存在
        validateCardDetailExists(id);
        // 删除
        cardDetailMapper.deleteById(id);
    }

    private void validateCardDetailExists(Long id) {
        if (cardDetailMapper.selectById(id) == null) {
//            throw exception(CARD_DETAIL_NOT_EXISTS);
        }
    }

    @Override
    public FruitCardDetailDO getCardDetail(Long id) {
        return cardDetailMapper.selectById(id);
    }

    @Override
    public List<FruitCardDetailDO> getCardDetailList(Collection<Long> ids) {
        return cardDetailMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<FruitCardDetailDO> getCardDetailPage(FruitCardDetailPageReqVO pageReqVO) {
        return cardDetailMapper.selectPage(pageReqVO);
    }

    @Override
    public List<FruitCardDetailDO> getCardDetailList(FruitCardDetailExportReqVO exportReqVO) {
        return cardDetailMapper.selectList(exportReqVO);
    }

}
